package com.spring.boot.utils;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * @program: springboot_vue
 * @description: 数据源切换
 * @author: ry
 * @create: 2018-08-15 16:02
 **/
public class MultipleDataSource extends AbstractRoutingDataSource {
    private static final ThreadLocal<String> dataSourceKey=new InheritableThreadLocal<String>();

    public static void setDataSourceKey(String dataSource){
        dataSourceKey.set(dataSource);
    }
    public static void ClearDataSourceKey() {
        dataSourceKey.remove();
    }
    @Override
    protected Object determineCurrentLookupKey() {
        return dataSourceKey.get();
    }
}
